<!--图片自动切换(带点击)-->
<html>
	<head>
		<meta charset="UTF-8">
		<title>js change img</title>
		<style type="text/css">
			#div{
				border: 1px solid red;
				position:relative; 
				margin:0 auto; 
				width:300px
			}
			#aa{
				position: absolute;
				left: -12px;
				top: 80px;
				color: lightgray;
				font-weight: bolder; 
				font-size:100px;
				text-decoration: none;
				display: none;
			}
			#ab{
				position: absolute;
				left: 236px;
				top: 80px;
				color: lightgray;
				font-weight: bolder; 
				font-size:100px;
				text-decoration: none;
				display: none;
			}
		</style>
	</head>
	<body >
		<div id="div">
			<img src="../public/imgs/1.jpg" id="img" width="300" height="300"/>
			<a href="#" id="aa" onclick="prev()">&lt;</a>
			<a href="#" id="ab" onclick="changeImg()">&gt;</a>
		</div>
	</body>
	<script type="text/javascript">
		var i=0;
		var img = document.getElementById("img");
		var aa=document.getElementById("aa");
		var ab=document.getElementById("ab");
		function changeImg(){
			i=i>=4?1:++i;
			img.src="../public/imgs/"+i+".jpg";
		}
		var stop= window.setInterval("changeImg()",2000);
		img.onmouseover = function(){
			clearInterval(stop);
			aa.style.display="block";
			ab.style.display="block";
		}
		aa.onmouseover = function(){
			clearInterval(stop);
			aa.style.display="block";
			ab.style.display="block";
		}
		ab.onmouseover = function(){
			clearInterval(stop);
			aa.style.display="block";
			ab.style.display="block";
		}
		img.onmouseout=function(){
			stop= window.setInterval("changeImg()",2000);
			aa.style.display="none";
			ab.style.display="none";
		}
		aa.onmouseout=function(){
			stop= window.setInterval("changeImg()",2000);
		}
		ab.onmouseout=function(){
			stop= window.setInterval("changeImg()",2000);
		}
		function prev(){
			i= i <= 1 ? 4 : --i;
			img.src="../public/imgs/"+i+".jpg";
		}
	</script>
</html>